﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Globalization;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class PS_HisEducationsInfo : System.Web.UI.UserControl
    {
        private SsMng ssMng = new SsMng();
        private IHisEducationBLL eduBLL = new HisEducationBLL();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected bool IsUserControlPostBack
        {
            get
            {
                return this.ViewState["IsUserControlPostBack"] != null;
            }
        }
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);
            IncludeJava();

            if (!IsUserControlPostBack)
            {
                this.ViewState.Add("IsUserControlPostBack", true);

                if (Request.QueryString["sta"] != null)
                    this.lblSta.Text = Request.QueryString["sta"].ToString();

                lblEmpSeq.Text = Session["emp_seq"].ToString();
                LoadDataGrid();
            }
        }
        public void IncludeJava()
        {
            HtmlGenericControl script = new HtmlGenericControl();
            script.TagName = "script";
            script.Attributes.Add("type", "text/javascript");
            script.Attributes.Add("src", "../../Scripts/jsfunction.js");
            Page.Header.Controls.Add(script);
        }
        public void LoadDataGrid()
        {
            DataSet ds = eduBLL.LoadEducationHistories((int?)null, lblEmpSeq.Text.Trim());
            DataTable dt = null;
            if (ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                RadGrid1.DataSource = dt;
                RadGrid1.DataBind();
            }
        }

        protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int seq = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["edu_seq"]);

                eduBLL.Delete(seq, ssMng.EmpSeqI);
            }
            if (e.CommandName == "btnClick")
            {
                return;
            }
            LoadDataGrid();
        }

        protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
             if (this.lblSta.Text == "v")
             {
                 RadGrid1.Columns[0].Visible = false;
                 RadGrid1.Columns[1].Visible = false;
             }          
        }

        protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is  GridCommandItem)
            {
                GridCommandItem commandItem = e.Item as GridCommandItem;
                LinkButton button = commandItem.FindControl("cmdAddNew") as LinkButton;

                if (this.lblSta.Text == "v")
                {
                    button.Enabled = false;
                    button.Visible = true;
                    button.Text = "";
                }
            }
        }
    }
}